Export StrictClickEvent type from StrictReactDOMProps#410
Conversation
This is useful when defining a callback, at least for typescript (otherwise, you need to redefined explicitly the type that match what a onClick could expect)
|
Well actually this is not enough. The type is not accessible anyway. Because otherwise, like said in the PR initial description, all the non-exported type at the package level need to be re-written. |
|
We use Flow to get the prop types from the component |
|
For TypeScript you can do something like the below: type StrictClickEventHandler = NonNullable<React.ComponentProps<typeof html.div>['onClick']>
// if you want to get the click event type itself
type StrictClickEvent = Parameters<StrictClickEventHandler>[0]
// or
type StrictClickEvent = StrictClickEventHandler extends (event: infer E) => any ? E : never
|
|
I think this type is a leftover from the early days when we had types like StrictHTMLElement. So it might be best to first FlowFixMe this event. Later we can properly type the event props to match what's expected on web |
|
Yeah sorry I am used to have named types and always forgot that I can go deeper into a type with typescript. |
|
Yeah that's a good idea! |
This is useful when defining a callback, at least for typescript (otherwise, you need to redefined explicitly the type that match what a onClick could expect).